package com.codingfuture.erp_system.web.controller;

import com.codingfuture.erp_system.dto.ChanageListDto;
import com.codingfuture.erp_system.dto.PageData;
import com.codingfuture.erp_system.entity.Emp;
import com.codingfuture.erp_system.entity.Goods;
import com.codingfuture.erp_system.entity.Store;
import com.codingfuture.erp_system.service.ChangeListService;
import com.codingfuture.erp_system.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v2")
public class ChangeListController {

    @Autowired
    private ChangeListService changeListService;

    @GetMapping("/storeoper")
    public Result findByAll(@RequestParam(defaultValue = "1") int page,
                            @RequestParam(defaultValue = "10") int rows,
                            ChanageListDto chanageListDto) {
        Page<ChanageListDto> page1 = PageHelper.startPage(page, rows);
        List<ChanageListDto> list;
        list = changeListService.findByAll(chanageListDto);
        PageData<ChanageListDto> data = new PageData<>(list, page1.getTotal());
        return Result.ok(data);
    }

    @GetMapping("/storeoper/emp_list")
    public Result findEmpList() {
        List<Emp> list = changeListService.findEmpList();
        return Result.OK(list);
    }

    @GetMapping("/storeoper/store_list")
    public Result findStoreList() {
        List<Store> list = changeListService.findStoreList();
        return Result.OK(list);
    }

    @GetMapping("/storeoper/goods_list")
    public Result findGoodsList() {
        List<Goods> list = changeListService.findGoodsList();
        return Result.OK(list);
    }
}
